package com.kemai.designmode.factory.static

import com.kemai.designmode.entry.Fruit
import com.kemai.designmode.entry.fruit.Apple
import com.kemai.designmode.entry.fruit.Banana
import com.kemai.designmode.entry.fruit.Orange

/**

 *@description:简单工厂模式
 * @author: zhaoshanshan
 * @date: 2022/10/3 8:29 上午

 */
 class StaticFactory {

    companion object{
        val instance:StaticFactory? by lazy(mode=LazyThreadSafetyMode.SYNCHRONIZED) {StaticFactory() }
    }

    fun getFruit(fruitType:Int):Fruit?{
        return when (fruitType) {
            1 -> {
                Apple()
            }
            2->{
                Banana()
            }
            3->{
                Orange()
            }
            else->{
                null
            }
        }

        }
    }

